//package com.atguigu.crowd.mvc.handler;/*
// *ClassNmae:TestHandler
// *Package:com.atguigu.crowd.mvc.handler
// *Description:
// *@Date:2020/6/13 21:41
// *@Author:1519524541@qq.com
// */
//
//import com.atguigu.crowd.entity.Admin;
//import com.atguigu.crowd.entity.ParamData;
//import com.atguigu.crowd.entity.Student;
//import com.atguigu.crowd.service.api.AdminService;
//import java.util.List;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.ModelMap;
//import org.springframework.web.bind.annotation.*;
//
//import javax.xml.ws.ResponseWrapper;
//
//@Controller
//public class TestHandler {
//
//    @Autowired
//    private AdminService adminService;
//    private Logger logger = LoggerFactory.getLogger(TestHandler.class);
//
//
//    @RequestMapping("/send/compose/object.json")
//    public @ResponseBody String testReceiveCOmposeObject(@RequestBody Student student){
//    logger.info(student.toString());
//        return "success";
//    }
//
//
//
//
//
//
//    @RequestMapping("/send/array/three.html")
//    public @ResponseBody String testReceiveArrayThree(@RequestBody List<Integer> array) {
//
//        for (Integer number : array) {
//            logger.info("number="+number);
//        }
//
//        return "success";
//    }
//
//    @ResponseBody
//    @RequestMapping("/send/array/two.html")
//    public String testReceiveArrayTwo(ParamData paramData) {
//
//        List<Integer> array = paramData.getArray();
//
//        for (Integer number : array) {
//            System.out.println("number="+number);
//        }
//
//        return "success";
//    }
//
//    @ResponseBody
//    @RequestMapping("/send/array/one.html")
//    public String testReceiveArrayOne(@RequestParam("array[]") List<Integer> array) {
//
//        for (Integer number : array) {
//            System.out.println("number="+number);
//        }
//
//        return "success";
//    }
//
//
//    }
//
//
package com.atguigu.crowd.mvc.handler;

import com.atguigu.crowd.entity.Admin;
import com.atguigu.crowd.entity.Student;
import com.atguigu.crowd.service.api.AdminService;
import com.atguigu.crowd.util.CrowdUtil;
import com.atguigu.crowd.util.ResultEntity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zzk
 * @create 2020-03-24 16:35
 */
@Controller
public class TestHandler {
    @Autowired
    private AdminService adminService;
    private Logger logger = LoggerFactory.getLogger(TestHandler.class);

    @RequestMapping("/test/ssm.html")
    public String testSsm(ModelMap modelMap, HttpServletRequest request) {
        boolean jjugeResult = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult="+jjugeResult);
        List<Admin> adminList =adminService.getAll();
        modelMap.addAttribute("adminList",adminList);
        String a = null;
        System.out.println(a.length());
        return "target";
    }

    @RequestMapping("/test/json.json")
    @ResponseBody
    public Admin testJson() {
        Admin admin = new Admin(1001, "jerry", "123456", "杰瑞", "jerry@qq.com", "now");
        return admin;
    }

    @ResponseBody
    @RequestMapping("/send/array.html")
    public String testReceiveArray(@RequestParam("array[]") List<Integer> array, HttpServletRequest request) {

        boolean judgeRequestType = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult="+judgeRequestType);
        System.out.println(10/0);
        return "success";
    }

    @ResponseBody
    @RequestMapping(value = "/send/obj.json")
    public ResultEntity<Student> testReceiveObj(@RequestBody Student student,HttpServletRequest request) {
        boolean judgeRequestType = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult="+judgeRequestType);
        System.out.println(10/0);
                ResultEntity<Student> resultEntity = ResultEntity.successWithoutData(student);
                    return resultEntity;
    }
}
